<template>
 <div class="box">
  <div class="mainContent">
   <div class="title-left">{{ $t('mining.mining') }}</div>

   <p class="info-tips">{{ $t('mining.tips') }}</p>

   <ul v-loading="loading">
    <li v-for="(item, index) of list" :key="index">
     <p class="state">{{ $t('mining.progress') }}</p>

     <h6>{{ item.name }}</h6>

     <div class="base">
      <div class="rate">
       <p class="rate-text">
        <span class="year-rate">{{ item.rateAmount }}%</span>
        <span class="day-rate">{{ item.rate }}%</span>
       </p>
       <p>{{ $t('mining.recent') }}</p>
      </div>
      <div class="time">
       <p>{{ item.days }} D</p>
       <p>{{ $t('mining.time') }}</p>
      </div>
     </div>

     <div class="speed">
      <el-progress :text-inside="true" :stroke-width="7" :percentage="item.sellRate" color="#0d4fa5"></el-progress>
      <p><span>{{ item.sellPrice }} CTB</span> / {{ item.totalPrice }} CTB</p>
     </div>

     <el-button type="primary" @click="details(item)">{{ $t('mining.join') }}</el-button>
    </li>
   </ul>
  </div>
 </div>
</template>

<script>
export default {
 name: "TabList",
 data: () => ({
  list: [],
  loading: false
 }),
 created() {
  this.tabList()
 },
 methods: {

  // 跳转详情
  details (e) {
   this.$router.push({
    path: '/productDetails',
    query:e
   })
  },

  // 获取列表
  tabList() {
   this.loading = true
   this.$post(this.$address.miner, {})
    .then(res => {
     console.log(res)
     this.loading = false
     if (res.code === 1) {
      res.data.forEach(item => {
       item.minPrice = item.minPrice.toFixed(2)
       item.maxPrice = item.maxPrice !== null ? item.maxPrice.toFixed(2) : 0
       item.percentage = Number((item.minPrice / item.maxPrice * 100).toFixed(0))
      })
      this.list = res.data
     }
    })
  }

 }
}
</script>

<style scoped lang="scss">
.box {
 display: flex;
 flex-direction: column;
 justify-content: center;
 align-items: center;

 .mainContent {
  display: flex;
  flex-direction: column;
  max-width: 935px;
  width: 95%;

  .title-left {
   display: flex;
   justify-content: flex-start;
   transform: translateY(-120%);
   font-size: 20px;
   align-items: center;
   padding-right: 40px;
   color: #ffffff;
   font-weight: 700;

   &:before {
    content: '';
    height: 40px;
    background-color: #fff;
    margin-right: 10px;
    width: 2px;
   }
  }

  >p {
   padding: 10px 20px;
   background-color: #F5FAFF;
   border-radius: 4px;
   font-size: 14px;
   box-shadow: 0 0 4px rgba(179,189,199,0.2);
   margin-bottom: 20px;
   color: grey;
  }

  ul {
   display: flex;
   flex-wrap: wrap;
   align-items: center;
   margin-top: 20px;
   justify-content: space-between;

   li {
    width: 440px;
    margin-bottom: 50px;
    border-radius: 4px;
    position: relative;
    background-color: #F5FAFF;
    -webkit-box-shadow: 0 2px 8px 0 rgba(202,215,224,0.52);
    box-shadow: 0 2px 8px 0 rgba(202,215,224,0.52);
    padding: 10px 20px 60px 20px;
    display: flex;
    flex-direction: column;
    max-width: 100%;

    .state {
     background-color: #01b364;
     padding: 2px 10px;
     margin-left: auto;
     color: #ffffff;
     font-size: 12px;
     position: absolute;
     right: 0;
     top: 0;
     border-bottom-left-radius: 6px;
    }

    >h6 {
     padding: 30px 0 0;
     color: #040404;
     font-size: 22px;
     margin-bottom: 30px;
     font-weight: bold;
    }

    .base {
     display: flex;
     align-items: center;
     justify-content: space-between;

     .rate {
      display: flex;
      flex-direction: column;

      .rate-text {
       display: flex;
       color: #01b364;
       align-items: baseline;

       .year-rate {
        font-size: 30px;
        font-weight: bold;
       }

       .day-rate {
        margin-left: 10px;
        font-size: 12px;
        padding: 4px 6px;
        border-radius: 4px;
        background-color: #ebf8f0;
       }
      }

      >p {
       color: #9496a1;
       font-size: 12px;
      }
     }

     .time {
      display: flex;
      flex-direction: column;

      p {
       &:nth-of-type(1) {
        font-size: 30px;
        font-weight: bold;
        color: #2a333a;
        display: block;
       }
       &:nth-of-type(2) {
        color: #9496a1;
        font-size: 14px;
       }
      }
     }
    }

    .speed {
     margin-top: 20px;

     .el-progress {
      /deep/ .el-progress-bar__outer {
       overflow: visible;

       .el-progress-bar__innerText {
        background-color: #0d4fa5;
        -webkit-transform: translateY(-35%);
        transform: translateY(-35%);
        padding: 2px 6px;
        border-radius: 100px;
        margin: 0;
        position: absolute;
        right: 0;
       }
      }
     }

     p {
      padding-top: 6px;
      padding-left: 4px;
      font-size: 12px;
      span {
       color: #0D4FA5;
      }
     }
    }

    .el-button {
     width: 50%;
     display: block;
     margin: 50px auto 0;
     padding: 8px 0;
     color: #fff;
     font-size: 16px;
     cursor: pointer;
     border-radius: 6px;
     background-color: #0D4FA5;
     border: none;
     height: 40px;
    }
   }
  }
 }
}
</style>
